import 'package:fish_redux/fish_redux.dart';
import 'package:www.znpigai.teacher/homework_detail_page/item/state.dart';

import 'action.dart';

Reducer<HomeworkAnswerState> buildReducer() {
  return asReducer(
    <Object, Reducer<HomeworkAnswerState>>{
      AnswerMarkAction.progress: _progress,
      AnswerMarkAction.rating: _rating,
    },
  );
}

HomeworkAnswerState _progress(HomeworkAnswerState state, Action action) {
  return state.clone()..webPageProgress = action.payload;
}

HomeworkAnswerState _rating(HomeworkAnswerState state, Action action) {
  var newState = state.clone();
  switch (action.payload['index']) {
    case 1:
      newState.rating1 = action.payload['rating'];
      break;
    case 2:
      newState.rating2 = action.payload['rating'];
      break;
    case 3:
      newState.rating3 = action.payload['rating'];
      break;
  }
  return newState;
}
